package action.point;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import service.PointService;
import util.Utilities;
import vo.PointVO;

import com.opensymphony.xwork2.ModelDriven;

public class PointInsertAction implements ModelDriven<PointVO>, SessionAware {
	private PointVO pvo = new PointVO();
	private PointService service;
	private String memberId;
	
	public void setPointService(PointService service) {
		this.service = service;   
	}
	public PointVO getModel(){
		return pvo;
	}
	 
	@Override
	public void setSession(Map<String, Object> session) {
		memberId = (String)session.get("member_id");
	}
	public String execute() {
//		System.out.println("action : "+ pvo.toString());
		try {
			pvo.setMemberId(memberId);
			service.insertPoint(pvo);
			pvo.setInfo(Utilities.changeTextToTag(pvo.getInfo()));
			pvo = service.selectOnePoint(pvo.getOrderId(), pvo.getProductId());
			System.out.println("action : "+ pvo.toString());
			
			return "success";
		} catch(Exception e) {
			e.printStackTrace();
			return "error";
		}
				
	}
}
